package lemna.top.chunyu.utils;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.io.IOUtils;

public class AppendUtils {
	public static void appendToFile(final InputStream in, final File f) throws IOException {
		OutputStream stream = null;
		try {
			stream = outStream(f);
			IOUtils.copy(in, stream);
			stream.close();
		} finally {
//			IOUtils.closeQuietly(stream);
		}
	}

	public static void appendToFile(final String in, final File f) throws IOException {
		InputStream stream = null;
		try {
			stream = IOUtils.toInputStream(in, "GBK");
			appendToFile(stream, f);
		} finally {
			IOUtils.closeQuietly(stream);
		}
	}

	private static OutputStream outStream(final File f) throws IOException {
		return new BufferedOutputStream(new FileOutputStream(f, true));
	}

	private AppendUtils() {
	}
}
